<template>
	<view class="content">
			<view class="waybill-details" ref="waybillDialog">
				<view class="title-box">
					<view class="tit1">
						<image src="imagesSuccess" class="logo" mode="widthFix"></image>
					</view>
					<view class="title">
						{{scanResult.result}}
					</view>
				</view>
				<view class="waybill-box">
						<view class="uni-form-item">
							<view class="title">车牌号：</view>
							<view class="val">{{scanResult.carBrand}}</view>
						</view>
						<view class="uni-form-item">
							<view class="title">煤型：</view>
							<view class="val">{{scanResult.proName}}</view>
						</view>
						<view class="uni-form-item"> 
							<view class="title">设备名称：</view>
							<view class="val">{{scanResult.deviceName}}</view>
						</view>
						<view class="uni-form-item">
							<view class="title">扫码时间：</view>
							<view class="val">{{scanResult.scanTime}}</view>
						</view>
						<view class="uni-form-item">
							<view class="title">装车排号：</view>
							<view class="val">{{scanResult.proId}}</view>
						</view>
						
				</view>
			</view>
	</view>
</template>
<script>
import func from '@/utils/funlogin.js';
import { getOpenId } from '@/utils/auth';
import { getScancode} from '@/api/me.js';
import { toast } from '@/utils/common';
import { getOpenIdByCode} from '@/api/login.js';
import config from '@/config'
export default {
	data() {
		return {
			deviceId: undefined,
			scanResult: {
				result: '',
				carBrand: '',
				proName: '',
				deviceName: '',
				scanTime: '',
				proId: ''
			}
		};
	},
  computed:{
    imagesSuccess(){
      if(this.$store.state.user.curTypeColor == "#D22C2C"){
        return  config.baseImgUrl + '/sucess1.png'
      }else if(this.$store.state.user.curTypeColor == "#409EFE"){
        return  config.baseImgUrl + '/sucess.png'
      }else{}
    }
  },
	methods: {
	    async getScancodes(){
		    //获取wx code
		    let code1 = await func.wxLogin();
		    console.log(code1,'这是获取的code================')
		    let openid = await getOpenIdByCode(code1);
		    console.log(openid.data,'这是获取的openid================')
			let data = {
				// "openId": getOpenId(),
				"openId": openid.data,
				"deviceId": this.deviceId
			}
			let res = await getScancode(data)
			console.log('司机扫码返回的res====',res)
			if(res.code == 200){
				this.scanResult.result  = res.message 
				this.scanResult.carBrand  = res.data.carBrand 
				this.scanResult.proName = res.data.proName
				this.scanResult.deviceName  = res.data.deviceName
				this.scanResult.scanTime  = res.data.scanTime
				
				if(!!res.data.proId){
					this.scanResult.proId  = res.data.proId.length < 7 ? res.data.proId : res.data.proId.substring(res.data.proId.length - 1)
				}
			}else{
				this.scanResult.result = res.msg
			}
		},
	},
	onLoad(options) {
		if(!!options){
			if(!!options.deviceId){
				this.deviceId = options.deviceId
				this.getScancodes()
			}
		}
	},
	onShow(){
	},
	onHide() {
	}
};
</script>

<style lang="scss" scoped>
.content {
	position: relative;
	padding: 20rpx;
	.waybill-details{
		position: relative;
		padding: 20rpx;
		background: #fff;
		border-radius: 8rpx;
		font-size: 24rpx;
		.title-box{
			border-bottom: 1px dashed #ccc;
			padding-bottom: 20rpx;
			text-align: center;
			font-size: 18px;
			color: #000;
			font-weight: bold;
			.title{
				padding-bottom: 15rpx;
			}
			.tit1{
				image{
					width: 218rpx;
					height: 188rpx;
				}
			}
		}
		.mzxx{
			border-bottom: 2rpx solid #cfe6f1;
			min-height: 50rpx;
			line-height: 38rpx;
			font-size: 28rpx;
			padding: 16rpx 0;
		}
		.waybill-box{
			margin: 10rpx;
			.uni-form-item{
				height: 50rpx!important;
				line-height: 50rpx;
				border: 0!important;
				font-size: 15px;
				display: flex;
				justify-content: space-between;
				margin-bottom: 0!important;
				.title{
					color: #999;
				}
				.val{
					color: #333;
				}
			}
		}
	}
}
</style>